﻿using Gqq.Common.Helper;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;

namespace GqqUnitTest
{
    
    
    /// <summary>
    ///这是 MathHelperTest 的测试类，旨在
    ///包含所有 MathHelperTest 单元测试
    ///</summary>
    [TestClass()]
    public class MathHelperTest
    {


        private TestContext testContextInstance;

        /// <summary>
        ///获取或设置测试上下文，上下文提供
        ///有关当前测试运行及其功能的信息。
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region 附加测试特性
        // 
        //编写测试时，还可使用以下特性:
        //
        //使用 ClassInitialize 在运行类中的第一个测试前先运行代码
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //使用 ClassCleanup 在运行完类中的所有测试后再运行代码
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //使用 TestInitialize 在运行每个测试前先运行代码
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //使用 TestCleanup 在运行完每个测试后运行代码
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        /// <summary>
        ///Add 的测试
        ///</summary>
        [TestMethod()]
        public void AddTest()
        {
            int a = 0; 
            int b = 0; 
            int expected = 0;
            int actual;
            actual = MathHelper.Add(a, b);
            Assert.AreEqual(expected, actual);

            a = 8;
            b = 9;
            var result = 17;
            actual = MathHelper.Add(a, b);
            Assert.AreEqual(result, actual);
//            Assert.Inconclusive("验证此测试方法的正确性。");
        }

        /// <summary>
        ///Divide 的测试
        ///</summary>
        [TestMethod()]
        public void DivideTest()
        {
            int a = 0;
            int b = 0;
            int expected = 0;
            int actual;
            actual = MathHelper.Divide(a, b);
            Assert.AreEqual(expected, actual);
//            Assert.Inconclusive("验证此测试方法的正确性。");
        }

        ///// <summary>
        /////GetValue 的测试
        /////</summary>
        //[TestMethod()]
        //public void GetValueTest()
        //{
        //    Decimal dc = new Decimal(); // TODO: 初始化为适当的值
        //    bool isDefault = false; // TODO: 初始化为适当的值
        //    Decimal expected = new Decimal(); // TODO: 初始化为适当的值
        //    Decimal actual;
        //    actual = MathHelper.GetValue(dc, isDefault);
        //    Assert.AreEqual(expected, actual);
        //    Assert.Inconclusive("验证此测试方法的正确性。");
        //}

        ///// <summary>
        /////Minus 的测试
        /////</summary>
        //[TestMethod()]
        //public void MinusTest()
        //{
        //    int a = 0; // TODO: 初始化为适当的值
        //    int b = 0; // TODO: 初始化为适当的值
        //    int expected = 0; // TODO: 初始化为适当的值
        //    int actual;
        //    actual = MathHelper.Minus(a, b);
        //    Assert.AreEqual(expected, actual);
        //    Assert.Inconclusive("验证此测试方法的正确性。");
        //}

        ///// <summary>
        /////Multiply 的测试
        /////</summary>
        //[TestMethod()]
        //public void MultiplyTest()
        //{
        //    int a = 0; // TODO: 初始化为适当的值
        //    int b = 0; // TODO: 初始化为适当的值
        //    int expected = 0; // TODO: 初始化为适当的值
        //    int actual;
        //    actual = MathHelper.Multiply(a, b);
        //    Assert.AreEqual(expected, actual);
        //    Assert.Inconclusive("验证此测试方法的正确性。");
        //}

        /// <summary>
        ///GetValue 的测试
        ///</summary>
        [TestMethod()]
        public void GetValueTest()
        {
            decimal dc = 5.126m;
            bool isDefault = false;
            Decimal expected = 5.13m;
            Decimal actual;
            actual = MathHelper.GetValue(dc, isDefault);
            Assert.AreEqual(expected, actual);

            dc = 5.123m;
            isDefault = false;
            expected = 5.12m;
            actual = MathHelper.GetValue(dc, isDefault);
            Assert.AreEqual(expected, actual);

            dc = 5.123m;
            isDefault = true;
            expected = 5.12m;
            actual = MathHelper.GetValue(dc, isDefault);
            Assert.AreEqual(expected, actual);

            dc = 5.126m;
            isDefault = false;
            expected = 5.13m;
            actual = MathHelper.GetValue(dc, isDefault);
            Assert.AreEqual(expected, actual);

            //四舍五入六成双
            dc = 5.125m;
            isDefault = true;
            expected = 5.12m;
            actual = MathHelper.GetValue(dc, isDefault);
            Assert.AreEqual(expected, actual);

            dc = 5.135m;
            isDefault = true;
            expected = 5.14m;
            actual = MathHelper.GetValue(dc, isDefault);
            Assert.AreEqual(expected, actual);

            dc = 5.135m;
            isDefault = false;
            expected = 5.14m;
            actual = MathHelper.GetValue(dc, isDefault);
            Assert.AreEqual(expected, actual);

            dc = 5.125m;
            isDefault = false;
            expected = 5.13m;
            actual = MathHelper.GetValue(dc, isDefault);
            Assert.AreEqual(expected, actual);
//            Assert.Inconclusive("验证此测试方法的正确性。");
        }
    }
}
